#include <UnitTest++.h>
#include <Math/Vector.hpp>
#include <Math/Array1.hpp>
#include <Math/Array2.hpp>
#include <Math/Random.hpp>
using namespace zzz;

SUITE(ArrayTest)
{
  TEST(Constructor) 
  {
    Vector<2,zuint> sizes(2,2);
    Array<2,float> x(2,2);
  }

  TEST(InterpolateTest2)
  {
    RandomReal<double> r;
    //2D imsymmetric
    Array<2,double> data2(2,2);
    for (zuint i=0; i<data2.size(); i++) data2[i]=r.Rand();
    Vector<2,double> coord;
    coord[0]=0.7; coord[1]=0.1;
    double ans=(data2(Vector2ui(0,0))*0.3+data2(Vector2ui(1,0))*0.7)*0.9+(data2(Vector2ui(0,1))*0.3+data2(Vector2ui(1,1))*0.7)*0.1;
    CHECK_CLOSE(ans,data2.Interpolate(coord),EPSILON);
  }

  TEST(InterpolateTest)
  {
    RandomReal<double> r;
    //1D
    Array<1,double> data1(2);
    for (zuint i=0; i<data1.size(); i++) data1[i]=r.Rand();
    CHECK_EQUAL(data1.Sum()/data1.size(),data1.Interpolate(0.5));

    //2D
    Array<2,double> data2(Vector<2,zuint>(2));
    for (zuint i=0; i<data2.size(); i++) data2[i]=r.Rand();
    CHECK_EQUAL(data2.Sum()/data2.size(),data2.Interpolate(Vector<2,double>(0.5)));

    //3D
    Array<3,double> data3(Vector<3,zuint>(2));
    for (zuint i=0; i<data3.size(); i++) data3[i]=r.Rand();
    CHECK_EQUAL(data3.Sum()/data3.size(),data3.Interpolate(Vector<3,double>(0.5)));

    //8D
    Array<8,double> data8(Vector<8,zuint>(2));
    for (zuint i=0; i<data8.size(); i++) data8[i]=r.Rand();
    CHECK_EQUAL(data8.Sum()/data8.size(),data8.Interpolate(Vector<8,double>(0.5)));
  }

}